<!DOCTYPE html>
<html lang="en">
  
  <head>
    <meta charset="UTF-8" />
    <title>注册</title>
    <meta charset="utf-8" name="keywords" content="{{.system.keywords}}" />
    <meta charset="utf-8" name="description" content="{{.system.description}}" />
    <link rel ="shortcut Icon" href="{{.system.pathname}}">
    <link rel="stylesheet" href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/pc/css/index.min.css?v=2" />
    <link rel="stylesheet" type="text/css" href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/pc/font/iconfont.css">
      <link rel="stylesheet" href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/admin/css/xcConfirm.css">
    <link rel="stylesheet" href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/admin/css/toast.css" />
    <style type="text/css">
      main{min-height: calc(100vh - 560px);}
    </style>
  </head>
  
  <body class="signin">
    <header>
      <div>
        <img src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/pc/img/pc/logo.gif" alt="统采商城">
      </div>
    </header>
    <main>
      <div class="inputBox">
        <p class="hd">欢迎注册统采商城</p>
        <form>
          <input type="text" name="mobile" placeholder="手机号码">
          <input type="password" name="password" placeholder="设置登录密码">
          <input type="number" name="code" placeholder="短信验证码"><span class="getCode" id="getcode">获取验证码</span>
          <p></p>
          <p></p>
          <p></p>
          <p></p>
          <p></p>
        </form>
        <button id="sign">立即注册</button>
      </div>
    </main>
    {{template "pc/public/foot.html" .}}
  </body>
  <script type="text/javascript" src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/pc/js/jquery.min.js"></script>
  <script type="text/javascript" src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/admin/js/xcConfirm.js"></script>
  <script type="text/javascript" src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/pc/js/toast.js"></script>
  <script type="text/javascript">
    // document.querySelector(".getCode").onclick = function(){
    //   var time = 60
    //   document.querySelector(".getCode").innerText = time + "秒后重试"
    //   var timer = setInterval(function(){
    //     if (time > 0) {
    //       time --
    //       document.querySelector(".getCode").innerText = time + "秒后重试"
    //     }else{
    //       clearInterval(timer)
    //       time = 60
    //       document.querySelector(".getCode").innerText = "获取验证码"
    //     }
    //   },1000)
    // }
    var yzm = 0;
    function timeout(){
    var time = 60;
    var tt = setInterval(function(){
      if (time == '0') {
        $('#getcode').text('重新获取验证码')
        clearInterval(tt)
        yzm = 0
      }else {
        time--
        $('#getcode').text(time+'秒后重新获取')
      }
    },1000)
  }
    $('#getcode').click(function(){
    var mobile=$("input[name=mobile]").val()
    if ( mobile== "") {
      mui.toast("请输入手机号码~")
    }else if (!/^1[3456789]\d{9}$/.test(mobile)) {
      mui.toast("请输入正确的号码~")
    } else {
      if (yzm == 0) {
        var that=this
        that.disabled=true
        $.ajax({
          url:'/mobile/login/smssend',
          data:{mobile:mobile,type:1,app:"fbe661719decefe5e632cf7cbd8fb737"},
          success:function(res){
            if(res==1){
              // mui.toast("验证码获取成功~")
              $('#getcode').text('60秒后重新获取')    
              timeout()
              yzm = 1
            }else if(res==0){
              showToast("服务繁忙,请稍后再试~")
            }else if(res==2){
              showToast("该号码未注册,请先注册~")
            }else{
              showToast("服务繁忙,请稍后再试~")
            }
            that.disabled=false
          },
          error:function(){
            showToast("服务繁忙,请稍后再试~")
            that.disabled=false
          }
        })
      }else {
        showToast("请稍后再在获取~")
      }
    }
  })
  $('#sign').click(function(){
    var type=$('#change').attr('data-type')
    var mobile=$("input[name=mobile]").val()
    if(!/^1[3456789]\d{9}$/.test(mobile)){
      showToast("请输入正确的号码~");
      return false;
    }
    if($("input[name=code]").val().length!=6){
      showToast("请输入验证码~");
      return false;
    }
    if($("input[name=password]").val()==""){
      showToast("请输入密码~");
      return false;
    }
    var that=this
    that.disabled=true
    var form=$('form').serialize()
    form+=`&style=`+type
    $.ajax({
      url:window.location.href,
      data:form,
      type:'post',
      success:function(res){
        console.log(res)
        if(res==1){
          showToast("注册成功")
          setTimeout(function(){
          if(document.referrer){
            if(document.referrer=="http://test.tongcaigou.com/login"){
              window.location.href="/my"
            }else{
              window.location.href=document.referrer
            }
          }else{
            window.location.href="/my"
          }
          },1000)
        }else if(res==2){
          showToast("号码已注册!");
        }else if(res==3){
          showToast("验证码错误!");
        }else if(res==0){
          showToast("网络繁忙,请稍后再试!");
        }else if(res==4){
          showToast("网络繁忙,请稍后再试!");
        }else{
          showToast("密码错误")
        }
        that.disabled=false
      },error:function(){
        showToast("服务繁忙,请稍后再试~")
        that.disabled=false
      }
    })
  })
  </script>
</html>